package com.logicwin.aibala.services.impl;

import com.logicwin.aibala.services.IScreenService;

import com.logicwin.aibala.Main;
import com.logicwin.aibala.Aibala;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;

public class ServiceManager  extends Service {
//	private static final String TAG = ServiceManager.class.getCanonicalName();
	private static boolean mStarted;
	private static Main mainActivity;	
	private static final ScreenService screenService = new ScreenService();
	@Override
	public IBinder onBind(Intent intent) {
		// TODO Auto-generated method stub
		return null;
	}
	@Override
	public void onCreate() {
		super.onCreate();
	}
	@Override
	public void onStart(Intent intent, int startId) {
		super.onStart(intent, startId);
		return;
		/*
		Bundle bundle = intent.getExtras();
		
		if(bundle != null && bundle.getBoolean(GlobalConfig.AUTOSTARTED)){
			ServiceManager.start();
			Log.i(TAG, "ServiceManager started");
		}
		
		SharedPreferences settings = getSharedPreferences(Main.class.getCanonicalName(), 0);
		SharedPreferences.Editor editor = settings.edit();
		editor.putBoolean(GlobalConfig.AUTOSTART, true);
		editor.commit();		
		*/
	}
	public void onDestroy(Intent intent, int startId) {
		super.onStart(intent, startId);
	}
	public void onStop(Intent intent, int startId) {
		super.onStart(intent, startId);
	}	

	public static boolean start() {
		if(ServiceManager.mStarted){
			return true;
		}
		
		// Start Android service
		Aibala.getContext().startService(
				new Intent(Aibala.getContext(), ServiceManager.class));
		ServiceManager.mStarted = true;
		return true;
	}
	
	public static IScreenService getScreenService() {
		return (IScreenService) ServiceManager.screenService;
	}
	
	public static void setMainActivity(Main mainActivity){
		ServiceManager.mainActivity = mainActivity;
	}
	
	public static Main getMainActivity(){
		return ServiceManager.mainActivity;
	}		
}
